<html>
<script type="text/javascript">
	function indexOf(arr, item) {
    var pos = arr.map(function(e, index) {
    	/* 1 0
    	   2 1
    	   3 2
    	   4 3
    	   5 4
    	  */
    	console.log("within Map, e: " + e + " index: " + index);
        return e === item ? index: -1;
    }).filter(function(e) {
    	/* -1
    	   1
    	   -1
    	  */
    	console.log("within filter, e: " + e);
        return e !== -1;
    });

    return pos.length === 0 ? -1 : pos[0];
}

console.log( indexOf([1,2,3,4,5], 2));

function indexOf2(arr, item) {
    	try {
          arr.forEach( (e, i) => {
            if (e === item) {
                Error().stack();
                throw new Error(i);
            }
        } );
      }
        catch (err) {
            return err.message;
        }
        return -1;
   
 }

console.log( indexOf2([1,2,3,4,5], 2));

</script>